<!DOCTYPE html>




<html class="theme-next mist" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hadoop,spark,hive,hbase,MapReduce,sqoop,scala," />








  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon-16x16-next.png?v=5.1.2" />






<meta name="description" content="Hadoop 安装以及（伪）分布式集群经典教程：Hadoop安装在阿里云中搭建大数据实验环境    —-仅有点儿参考价值 注解：12345678910111213/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行，并从/etc/profile.d目录的配置文件中搜集shell的设置，/etc/bashrc:为每一个运行bash shell的用户执行此文件">
<meta name="keywords" content="Hadoop,spark,hive,hbase,MapReduce,sqoop,scala">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop入门笔记">
<meta property="og:url" content="http://xchcloud.cn/Hadoop入门笔记/index.html">
<meta property="og:site_name" content="超哥记录日记">
<meta property="og:description" content="Hadoop 安装以及（伪）分布式集群经典教程：Hadoop安装在阿里云中搭建大数据实验环境    —-仅有点儿参考价值 注解：12345678910111213/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行，并从/etc/profile.d目录的配置文件中搜集shell的设置，/etc/bashrc:为每一个运行bash shell的用户执行此文件">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-06-01T12:00:00.378Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hadoop入门笔记">
<meta name="twitter:description" content="Hadoop 安装以及（伪）分布式集群经典教程：Hadoop安装在阿里云中搭建大数据实验环境    —-仅有点儿参考价值 注解：12345678910111213/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行，并从/etc/profile.d目录的配置文件中搜集shell的设置，/etc/bashrc:为每一个运行bash shell的用户执行此文件">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: false,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://xchcloud.cn/Hadoop入门笔记/"/>





  <title>Hadoop入门笔记 | 超哥记录日记</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b8d23512908ca3b4b175b2620a75740f";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">超哥记录日记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">生命有息、学无止境、折腾不止</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://xchcloud.cn/Hadoop入门笔记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="John Doe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://tuchuang-xchcloud-1253428588.cos.ap-chengdu.myqcloud.com/blog/header.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="超哥记录日记">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">Hadoop入门笔记</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-06-01T09:43:27+08:00">
                2019-06-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/大数据/" itemprop="url" rel="index">
                    <span itemprop="name">大数据</span>
                  </a>
                </span>

                
                
              
            </span>
          

 


          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o">访问数</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>°C
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  4,049
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  17
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Hadoop-安装以及（伪）分布式集群"><a href="#Hadoop-安装以及（伪）分布式集群" class="headerlink" title="Hadoop 安装以及（伪）分布式集群"></a>Hadoop 安装以及（伪）分布式集群</h2><h3 id="经典教程："><a href="#经典教程：" class="headerlink" title="经典教程："></a>经典教程：</h3><p><a href="http://dblab.xmu.edu.cn/blog/1258-2/" target="_blank" rel="noopener">Hadoop安装</a><br><a href="http://dblab.xmu.edu.cn/blog/1952-2/" target="_blank" rel="noopener">在阿里云中搭建大数据实验环境</a>    —-仅有点儿参考价值</p>
<h3 id="注解："><a href="#注解：" class="headerlink" title="注解："></a>注解：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行，并</span><br><span class="line">从/etc/profile.d目录的配置文件中搜集shell的设置，</span><br><span class="line"></span><br><span class="line">/etc/bashrc:为每一个运行bash shell的用户执行此文件，当bash shell被打开时,该文件被</span><br><span class="line">读取。</span><br><span class="line"></span><br><span class="line">~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,</span><br><span class="line">该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。</span><br><span class="line"></span><br><span class="line">~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell</span><br><span class="line">时,该文件被读取。</span><br><span class="line"></span><br><span class="line">***hadoop 的 JAVA 变量必须在 ~/.bashrc，尽量使用 1.8 版本，后面的 sbt 版本要求是 1.8***</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Hadoop 附带了丰富的例子（运行 </span><br><span class="line">./bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar </span><br><span class="line">可以看到所有例子），包括 wordcount、terasort、join、grep 等。</span><br><span class="line"></span><br><span class="line">在此我们选择运行 grep 例子，我们将 input 文件夹中的所有文件作为输入，筛选当中符合正</span><br><span class="line">则表达式 dfs[a-z.]+ 的单词并统计出现的次数，最后输出结果到 output 文件夹中。</span><br><span class="line"></span><br><span class="line">注意，Hadoop 默认不会覆盖结果文件，因此再次运行上面实例会提示出错，需要先将 ./output 删除。</span><br><span class="line">rm -r ./output</span><br></pre></td></tr></table></figure>
<h3 id="hadoop-命令"><a href="#hadoop-命令" class="headerlink" title="hadoop 命令"></a>hadoop 命令</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">启动/关闭：</span><br><span class="line"></span><br><span class="line">start-all.sh   //这个 hadoop 启动命令会和 spark 命令重复，所以会提示缺少一个</span><br><span class="line">spark的jar包，不影响hadoop的启动。要再执行下 jobhistory 脚本</span><br><span class="line"></span><br><span class="line">start-dfs.sh</span><br><span class="line">start-yarn.sh</span><br><span class="line">mr-jobhistory-daemon.sh start historyserver  //支持查看作业历史运行信息</span><br><span class="line"></span><br><span class="line">如何通过Web查看job的运行情况: https://www.linuxidc.com/Linux/2015-05/117501.htm</span><br><span class="line"></span><br><span class="line">http://master:50070/</span><br><span class="line">http://master:8088/cluster</span><br><span class="line"></span><br><span class="line">HDFS操作常用Shell命令：http://dblab.xmu.edu.cn/blog/1625-2/</span><br><span class="line">HDFS Shell命令官方文档：http://hadoop.apache.org/docs/r2.5.2/hadoop-project-dist/hadoop-common/FileSystemShell.html</span><br></pre></td></tr></table></figure>
<h2 id="利用Java-API与HDFS进行交互"><a href="#利用Java-API与HDFS进行交互" class="headerlink" title="利用Java API与HDFS进行交互"></a>利用Java API与HDFS进行交互</h2><h3 id="经典教程：-1"><a href="#经典教程：-1" class="headerlink" title="经典教程："></a>经典教程：</h3><p><a href="http://dblab.xmu.edu.cn/blog/290-2/" target="_blank" rel="noopener">大数据技术原理与应用 第三章 分布式文件系统HDFS 学习指南</a></p>
<p><a href="http://hadoop.apache.org/docs/stable/api/" target="_blank" rel="noopener">HAdoop API</a></p>
<h3 id="爬坑"><a href="#爬坑" class="headerlink" title="爬坑"></a>爬坑</h3><p>注：</p>
<p>有可能会报错，原因需要代码中添加用户名、密码。</p>
<h2 id="hbase"><a href="#hbase" class="headerlink" title="hbase"></a>hbase</h2><p>HBase是一个分布式的、面向列的开源数据库,一个结构化数据的分布式存储系统”。就像Bigtable利用了Google文件系统（File System）所提供的分布式数据存储一样，HBase在Hadoop之上提供了类似于Bigtable的能力。HBase是Apache的Hadoop项目的子项目。HBase不同于一般的关系数据库，它是一个适合于<strong>非结构化数据存储的数据库</strong>。另一个不同的是<strong>HBase基于列的而不是基于行的模式</strong>。</p>
<h3 id="经典教程：-2"><a href="#经典教程：-2" class="headerlink" title="经典教程："></a>经典教程：</h3><p><a href="http://dblab.xmu.edu.cn/blog/install-hbase/" target="_blank" rel="noopener">大数据原理与应用 第四章 分布式数据库HBase 学习指南</a></p>
<h3 id="笔记"><a href="#笔记" class="headerlink" title="笔记"></a>笔记</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">运行HBase:</span><br><span class="line">第一步：首先启动Hadoop，如果已经启动hadoop请跳过此步骤。命令如下：</span><br><span class="line"></span><br><span class="line">start-all.sh</span><br><span class="line"></span><br><span class="line">第二步：切换目录至/usr/local/hbase;再启动HBase.命令如下：</span><br><span class="line"></span><br><span class="line">cd /usr/local/hbase</span><br><span class="line">./bin/start-hbase.sh</span><br><span class="line"></span><br><span class="line">进入HBase Shell交互式执行环境：</span><br><span class="line"></span><br><span class="line">cd /usr/local/hbase</span><br><span class="line">./bin/hbase shell</span><br><span class="line"></span><br><span class="line">Hadoop的HDFS中查看变化：</span><br><span class="line"></span><br><span class="line">linziyu@iZbp11gznj7n38xkztu64dZ:/usr/local/hadoop$ ./bin/hdfs dfs -ls /</span><br><span class="line">Found 2 items</span><br><span class="line">drwxr-xr-x   - linziyu supergroup          0 2018-04-11 17:35 /hbase</span><br><span class="line">drwxr-xr-x   - linziyu supergroup          0 2018-04-06 22:40 /user</span><br><span class="line">可以看到，在HDFS中，自动生成了一个“/hbase”目录，用来保存HBase的数据。</span><br><span class="line"></span><br><span class="line">注意：如果在操作HBase的过程中发生错误，可以通过&#123;HBASE_HOME&#125;目录</span><br><span class="line">（/usr/local/hbase）下的logs子目录中的日志文件查看错误原因。</span><br><span class="line">这里启动关闭Hadoop和HBase的顺序一定是：</span><br><span class="line">启动Hadoop—&gt;启动HBase—&gt;关闭HBase—&gt;关闭Hadoop</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ERROR: Can&apos;t get master address from ZooKeeper; znode data == null</span><br><span class="line">as:</span><br><span class="line">重启hbase（可能是zookeeper或hbase不稳定造成的 重启不一定起作用）</span><br><span class="line">or</span><br><span class="line">执行hdfs格式化命令：hadoop namenode -format  (删除临时文件/格式化)</span><br></pre></td></tr></table></figure>
<h3 id="HBase-常用Shell命令"><a href="#HBase-常用Shell命令" class="headerlink" title="HBase 常用Shell命令"></a>HBase 常用Shell命令</h3><table>
<thead>
<tr>
<th>hbase shell命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>alter</td>
<td>修改列族（column family）模式</td>
</tr>
<tr>
<td>count</td>
<td>统计表中行的数量</td>
</tr>
<tr>
<td>create</td>
<td>创建表</td>
</tr>
<tr>
<td>describe</td>
<td>显示表相关的详细信息</td>
</tr>
<tr>
<td>delete</td>
<td>删除指定对象的值（可以为表，行，列对应的值，另外也可以指定时间戳的值）</td>
</tr>
<tr>
<td>deleteall</td>
<td>删除指定行的所有元素值</td>
</tr>
<tr>
<td>disable</td>
<td>使表无效</td>
</tr>
<tr>
<td>drop</td>
<td>删除表</td>
</tr>
<tr>
<td>enable</td>
<td>使表有效</td>
</tr>
<tr>
<td>exists</td>
<td>测试表是否存在</td>
</tr>
<tr>
<td>exit</td>
<td>退出hbase shell</td>
</tr>
<tr>
<td>get</td>
<td>获取行或单元（cell）的值</td>
</tr>
<tr>
<td>incr</td>
<td>增加指定表，行或列的值</td>
</tr>
<tr>
<td>list</td>
<td>列出hbase中存在的所有表</td>
</tr>
<tr>
<td>put</td>
<td>向指向的表单元添加值</td>
</tr>
<tr>
<td>tools</td>
<td>列出hbase所支持的工具</td>
</tr>
<tr>
<td>scan</td>
<td>通过对表的扫描来获取对用的值</td>
</tr>
<tr>
<td>status</td>
<td>返回hbase集群的状态信息</td>
</tr>
<tr>
<td>shutdown</td>
<td>关闭hbase集群（与exit不同）</td>
</tr>
<tr>
<td>truncate</td>
<td>重新创建指定表</td>
</tr>
<tr>
<td>version</td>
<td>返回hbase版本信息</td>
</tr>
</tbody>
</table>
<h4 id="表的管理"><a href="#表的管理" class="headerlink" title="表的管理"></a>表的管理</h4><p>1）通过list可以列出所有已创建的表(除-ROOT表和.META表(被过滤掉了))</p>
<p><code>hbase(main)&gt; list</code></p>
<p>2）创建表，其中t1是表名，f1、f2是t1的列族。hbase中的表至少有一个列族.它们之中，列族直接影响hbase数据存储的物理特性。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">语法：create &lt;table&gt;, &#123;NAME =&gt; &lt;family&gt;, VERSIONS =&gt; &lt;VERSIONS&gt;&#125; </span><br><span class="line"></span><br><span class="line">例如：创建表t1，有两个family name：f1，f2，且版本数均为2</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; create &apos;t1&apos;,&#123;NAME =&gt; &apos;f1&apos;, VERSIONS =&gt; 2&#125;,&#123;NAME =&gt; &apos;f2&apos;, VERSIONS =&gt; 2&#125;</span><br></pre></td></tr></table></figure></p>
<p>3）删除表<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">分两步：首先disable，然后drop</span><br><span class="line">例如：删除表t1</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; disable &apos;t1&apos;</span><br><span class="line">hbase(main)&gt; drop &apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<p>4）查看表的结构<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">语法：describe(desc) &lt;table&gt; （可以看到这个表的所有默认参数）</span><br><span class="line">例如：查看表t1的结构</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; describe &apos;t1&apos; / desc  &apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<p>5）修改表结构<br>修改表结构必须先disable<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法：alter &apos;t1&apos;, &#123;NAME =&gt; &apos;f1&apos;&#125;, &#123;NAME =&gt; &apos;f2&apos;, METHOD =&gt; &apos;delete&apos;&#125;</span><br><span class="line">例如：修改表test1的cf的TTL为180天</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; disable &apos;test1&apos;</span><br><span class="line">hbase(main)&gt; alter &apos;test1&apos;,&#123;NAME=&gt;&apos;body&apos;,TTL=&gt;&apos;15552000&apos;&#125;,&#123;NAME=&gt;&apos;meta&apos;, TTL=&gt;&apos;15552000&apos;&#125;</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; enable &apos;test1&apos;</span><br></pre></td></tr></table></figure></p>
<p>6)查看表中所有记录 scan<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">语法：scan &apos;tablename&apos;</span><br><span class="line"></span><br><span class="line">scan &apos;wc&apos;</span><br></pre></td></tr></table></figure></p>
<p>7)alter<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">语法：alter ‘tablename’,NAME=&gt;’familyname’,attribute=&gt;new_value </span><br><span class="line"></span><br><span class="line">例子：给表添加列族 alter</span><br><span class="line">添加一个名字叫sid的列族VERSIONS值为5</span><br><span class="line"></span><br><span class="line">alter &apos;wc&apos;,NAME=&gt;&apos;sid&apos;,VERSION=&gt;5</span><br></pre></td></tr></table></figure></p>
<p>8）删除列族，需首先将表disable<br><code>alter ‘tablename’,’delete’=&gt;’column family’</code><br>删除一个列族之后，这个列族的数据也会全部被删除。<br>9)删除表范围运算符，需首先将表disable<br><code>alter ‘tablename’,METHOD=&gt;’table_att_unset’,NAME=&gt;’MAX_FILESIZE’</code><br>10)incr 计数器<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">incr &apos;tablename&apos;,&apos;rowkey&apos;,&apos;column family:column&apos; step     </span><br><span class="line">step是步长，可选，默认为1</span><br><span class="line"></span><br><span class="line">给‘id’这个行健增加&apos;column_famaly1:addr&apos;字段，并使用counter实现递增</span><br></pre></td></tr></table></figure></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">hbase(main):002:0&gt; incr &apos;table&apos;,&apos;id&apos;,&apos;column_famaly1:addr&apos;</span><br><span class="line">COUNTER VALUE = 1</span><br><span class="line">0 row(s) </span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">hbase(main):003:0&gt; incr &apos;table&apos;,&apos;id&apos;,&apos;column_famaly1:addr&apos;</span><br><span class="line">COUNTER VALUE = 2</span><br><span class="line">0 row(s) </span><br><span class="line"> </span><br><span class="line">hbase(main):004:0&gt; get &apos;table&apos;,&apos;id&apos;,&apos;column_famaly1:addr&apos;</span><br><span class="line">COLUMN                CELL                                                      </span><br><span class="line"> column_famaly1:addr  timestamp=1463056705124, value=\x00\x00\x00\x00\x00\x00\x0</span><br><span class="line">                      0\x02                                                     </span><br><span class="line">1 row(s) </span><br><span class="line"> </span><br><span class="line">hbase(main):005:0&gt; incr &apos;table&apos;,&apos;id&apos;,&apos;column_famaly1:addr&apos;</span><br><span class="line">COUNTER VALUE = 3</span><br><span class="line">0 row(s)</span><br></pre></td></tr></table></figure>
<p>11)获取计数器当前值</p>
<p><code>get_counter &#39;tablename&#39;,&#39;rowkey&#39;,&#39;column family:column&#39;</code></p>
<h4 id="权限管理"><a href="#权限管理" class="headerlink" title="权限管理"></a>权限管理</h4><p>1）分配权限<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">语法 : grant &lt;user&gt; &lt;permissions&gt; &lt;table&gt; &lt;column family&gt; &lt;column qualifier&gt; 参数后面用逗号分隔</span><br><span class="line"></span><br><span class="line">权限用五个字母表示： &quot;RWXCA&quot;.</span><br><span class="line"></span><br><span class="line">READ(&apos;R&apos;), WRITE(&apos;W&apos;), EXEC(&apos;X&apos;), CREATE(&apos;C&apos;), ADMIN(&apos;A&apos;)</span><br><span class="line"></span><br><span class="line">例如，给用户‘test&apos;分配对表t1有读写的权限，</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; grant &apos;test&apos;,&apos;RW&apos;,&apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<p>2）查看权限<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">语法：user_permission &lt;table&gt;</span><br><span class="line">例如，查看表t1的权限列表</span><br><span class="line">hbase(main)&gt; user_permission &apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<p>3）收回权限<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">与分配权限类似，语法：revoke &lt;user&gt; &lt;table&gt; &lt;column family&gt; &lt;column qualifier&gt;</span><br><span class="line">例如，收回test用户在表t1上的权限</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; revoke &apos;test&apos;,&apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<p>4)将表设置为只读模式<br><code>alter ‘tablename’,READONLY</code></p>
<h4 id="表数据的增删改查"><a href="#表数据的增删改查" class="headerlink" title="表数据的增删改查"></a>表数据的增删改查</h4><h5 id="添加数据"><a href="#添加数据" class="headerlink" title="添加数据"></a>添加数据</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">语法：put &lt;table&gt;,&lt;rowkey&gt;,&lt;family:column&gt;,&lt;value&gt;,&lt;timestamp&gt;</span><br><span class="line"></span><br><span class="line">例如：给表t1的添加一行记录：rowkey是rowkey001，family name：f1，column name：col1，value：value01，timestamp：系统默认</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; put &apos;t1&apos;,&apos;rowkey001&apos;,&apos;f1:col1&apos;,&apos;value01&apos;</span><br></pre></td></tr></table></figure>
<h5 id="查询数据"><a href="#查询数据" class="headerlink" title="查询数据"></a>查询数据</h5><p>a）查询某行记录<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">语法：get &lt;table&gt;,&lt;rowkey&gt;,[&lt;family:column&gt;,....]</span><br><span class="line"></span><br><span class="line">例如：查询表t1，rowkey001中的f1下的col1的值</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; get &apos;t1&apos;,&apos;rowkey001&apos;, &apos;f1:col1&apos;</span><br><span class="line">或者：</span><br><span class="line">hbase(main)&gt; get &apos;t1&apos;,&apos;rowkey001&apos;, &#123;COLUMN=&gt;&apos;f1:col1&apos;&#125;</span><br><span class="line"></span><br><span class="line">查询表t1，rowke002中的f1下的所有列值</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; get &apos;t1&apos;,&apos;rowkey001&apos;</span><br></pre></td></tr></table></figure></p>
<p>b）扫描表<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法：scan &lt;table&gt;, &#123;COLUMNS =&gt; [ &lt;family:column&gt;,.... ], LIMIT =&gt; num&#125;</span><br><span class="line"></span><br><span class="line">另外，还可以添加STARTROW、TIMERANGE和FITLER等高级功能</span><br><span class="line"></span><br><span class="line">例如：扫描表t1的前5条数据</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; scan &apos;t1&apos;,&#123;LIMIT=&gt;5&#125;</span><br></pre></td></tr></table></figure></p>
<p>c）查询表中的数据行数<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法：count &lt;table&gt;, &#123;INTERVAL =&gt; intervalNum, CACHE =&gt; cacheNum&#125;</span><br><span class="line">INTERVAL设置多少行显示一次及对应的rowkey，默认1000；CACHE每次去取的缓存区大小，默</span><br><span class="line">认是10，调整该参数可提高查询速度</span><br><span class="line"></span><br><span class="line">例如，查询表t1中的行数，每100条显示一次，缓存区为500</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; count &apos;t1&apos;, &#123;INTERVAL =&gt; 100, CACHE =&gt; 500&#125;</span><br></pre></td></tr></table></figure></p>
<h5 id="删除数据"><a href="#删除数据" class="headerlink" title="删除数据"></a>删除数据</h5><p>a )删除行中的某个列值<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法：delete &lt;table&gt;, &lt;rowkey&gt;,  &lt;family:column&gt; , &lt;timestamp&gt;,必须指定列名</span><br><span class="line"></span><br><span class="line">例如：删除表t1，rowkey001中的f1:col1的数据</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; delete &apos;t1&apos;,&apos;rowkey001&apos;,&apos;f1:col1&apos;</span><br><span class="line"></span><br><span class="line">注：将删除改行f1:col1列所有版本的数据</span><br></pre></td></tr></table></figure></p>
<p>b )删除行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">语法：deleteall &lt;table&gt;, &lt;rowkey&gt;,  &lt;family:column&gt; , &lt;timestamp&gt;，可以不指定列名，删除整行数据</span><br><span class="line"></span><br><span class="line">例如：删除表t1，rowk001的数据</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; deleteall &apos;t1&apos;,&apos;rowkey001&apos;</span><br></pre></td></tr></table></figure></p>
<p>c）删除表中的所有数据<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">语法： truncate &lt;table&gt;</span><br><span class="line"></span><br><span class="line">其具体过程是：disable table -&gt; drop table -&gt; create table</span><br><span class="line"></span><br><span class="line">例如：删除表t1的所有数据</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; truncate &apos;t1&apos;</span><br></pre></td></tr></table></figure></p>
<h4 id="组命令Group-name"><a href="#组命令Group-name" class="headerlink" title="组命令Group name"></a>组命令Group name</h4><p>1)查看当前集群状态</p>
<p><code>status</code></p>
<p>2)查看当前用户是谁</p>
<p><code>whoami</code></p>
<p>3)创建命名空间</p>
<p><code>create_namespace &#39;ns name&#39;</code></p>
<p>4)查看有哪些命名空间</p>
<p><code>list_namespace</code></p>
<p>5)删除命名空间</p>
<p><code>drop_namespace &#39;ns name&#39;</code></p>
<h4 id="Region管理"><a href="#Region管理" class="headerlink" title="Region管理"></a>Region管理</h4><p>1）移动region<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">语法：move &apos;encodeRegionName&apos;, &apos;ServerName&apos;</span><br><span class="line"></span><br><span class="line">encodeRegionName指的regioName后面的编码，ServerName指的是master-status的Region Servers列表</span><br><span class="line"></span><br><span class="line">示例:</span><br><span class="line">hbase(main)&gt;move &apos;4343995a58be8e5bbc739af1e91cd72d&apos;, &apos;db-41.xxx.xxx.org,60020,1390274516739&apos;</span><br></pre></td></tr></table></figure></p>
<p>2）开启/关闭region<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">语法：balance_switch true|false</span><br><span class="line"></span><br><span class="line">hbase(main)&gt; balance_switch</span><br></pre></td></tr></table></figure></p>
<p>3）手动split</p>
<p><code>语法：split &#39;regionName&#39;, &#39;splitKey&#39;</code></p>
<p>4）手动触发major compaction<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">语法：</span><br><span class="line">Compact all regions in a table:</span><br><span class="line">hbase&gt; major_compact &apos;t1&apos;</span><br><span class="line">Compact an entire region:</span><br><span class="line">hbase&gt; major_compact &apos;r1&apos;</span><br><span class="line">Compact a single column family within a region:</span><br><span class="line">hbase&gt; major_compact &apos;r1&apos;, &apos;c1&apos;</span><br><span class="line">Compact a single column family within a table:</span><br><span class="line">hbase&gt; major_compact &apos;t1&apos;, &apos;c1&apos;</span><br></pre></td></tr></table></figure></p>
<h4 id="配置管理及节点重启"><a href="#配置管理及节点重启" class="headerlink" title="配置管理及节点重启"></a>配置管理及节点重启</h4><p>1）修改hdfs配置<br><code>hdfs配置位置：/etc/hadoop/conf</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">同步hdfs配置</span><br><span class="line"></span><br><span class="line">cat /home/hadoop/slaves|xargs -i -t scp /etc/hadoop/conf/hdfs-site.xml hadoop@&#123;&#125;:/etc/hadoop/conf/hdfs-site.xml</span><br><span class="line"></span><br><span class="line">关闭：</span><br><span class="line"></span><br><span class="line">cat /home/hadoop/slaves|xargs -i -t ssh hadoop@&#123;&#125; &quot;sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf stop datanode&quot;</span><br><span class="line"></span><br><span class="line">启动：</span><br><span class="line"></span><br><span class="line">cat /home/hadoop/slaves|xargs -i -t ssh hadoop@&#123;&#125; &quot;sudo /home/hadoop/cdh4/hadoop-2.0.0-cdh4.2.1/sbin/hadoop-daemon.sh --config /etc/hadoop/conf start datanode&quot;</span><br></pre></td></tr></table></figure></p>
<p>2）修改hbase配置<br>hbase配置位置：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">同步hbase配置</span><br><span class="line"></span><br><span class="line">cat /home/hadoop/hbase/conf/regionservers|xargs -i -t scp /home/hadoop/hbase/conf/hbase-site.xml hadoop@&#123;&#125;:/home/hadoop/hbase/conf/hbase-site.xml</span><br><span class="line"> </span><br><span class="line">graceful重启</span><br><span class="line"></span><br><span class="line">cd ~/hbase</span><br><span class="line">bin/graceful_stop.sh --restart --reload --debug inspurXXX.xxx.xxx.org</span><br></pre></td></tr></table></figure></p>
<h2 id="MapReduce"><a href="#MapReduce" class="headerlink" title="MapReduce"></a>MapReduce</h2><p>MapReduce是一种编程模型，用于大规模数据集（大于1TB）的并行运算。概念”Map（映射）”和”Reduce（归约）”，是它们的主要思想，都是从函数式编程语言里借来的，还有从矢量编程语言里借来的特性。</p>
<p>MapReduce是面向大数据并行处理的计算模型、框架和平台。</p>
<h3 id="经典教程：-3"><a href="#经典教程：-3" class="headerlink" title="经典教程："></a>经典教程：</h3><p><a href="大数据技术原理与应用">大数据技术原理与应用 MOOC 慕课</a><br><a href="http://dblab.xmu.edu.cn/blog/hadoop-build-project-using-eclipse/" target="_blank" rel="noopener">使用Eclipse编译运行MapReduce程序_Hadoop2.6.0_Ubuntu/CentOS</a><br><a href="http://dblab.xmu.edu.cn/blog/hadoop-build-project-by-shell/" target="_blank" rel="noopener">使用命令行编译打包运行自己的MapReduce程序 Hadoop2.6.0</a></p>
<h3 id="爬坑-1"><a href="#爬坑-1" class="headerlink" title="爬坑"></a>爬坑</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">error：</span><br><span class="line">hadoop@Master:/usr/local/hadoop$ bin/hdfs dfs -put etc/hadoop input</span><br><span class="line">put: `input&apos;: No such file or directory</span><br><span class="line"></span><br><span class="line">as: 主要是命令老了吧</span><br><span class="line">hadoop@Master:/usr/local/hadoop$ ./bin/hdfs dfs -mkdir -p /user/hadoop</span><br><span class="line">hadoop@Master:/usr/local/hadoop$ ./bin/hdfs dfs -mkdir -p /user/hadoop/input</span><br><span class="line">hadoop@Master:/usr/local/hadoop$ hadoop fs -put /usr/local/hadoop/etc/hadoop/hdfs-site.xml /user/hadoop/input</span><br><span class="line">hadoop@Master:/usr/local/hadoop$ hadoop fs -put /usr/local/hadoop/etc/hadoop/core-site.xml /user/hadoop/input</span><br><span class="line"></span><br><span class="line">error:</span><br><span class="line">有时候一些 eclipse 插件安装之后，打开 eclipse 死活都不显示</span><br><span class="line">as:</span><br><span class="line">把 eclipse/configuration/org.eclipse.update 删除掉</span><br></pre></td></tr></table></figure>
<h2 id="Hive-（数据仓库工具）"><a href="#Hive-（数据仓库工具）" class="headerlink" title="Hive （数据仓库工具）"></a>Hive （数据仓库工具）</h2><p>hive 是基于Hadoop的一个数据仓库工具，可以将结构化的数据文件映射为一张数据库表，并提供简单的sql查询功能，可以将sql语句转换为MapReduce任务进行运行。 其优点是学习成本低，可以通过类SQL语句快速实现简单的MapReduce统计，不必开发专门的MapReduce应用，十分适合数据仓库的统计分析。</p>
<p>Hue 是cdh专门的一套web管理器，它包括3个部分hue ui，hue server，hue db。hue提供所有的cdh组件的shell界面的接口。你可以在hue编写mr，查看修改hdfs的文件，管理hive的元数据，运行Sqoop，编写Oozie工作流等大量工作。</p>
<h3 id="经典教程"><a href="#经典教程" class="headerlink" title="经典教程"></a>经典教程</h3><p><a href="http://dblab.xmu.edu.cn/blog/1080-2/" target="_blank" rel="noopener">大数据技术原理与应用 第十四章 基于Hadoop的数据仓库Hive 学习指南</a>—–包含基本命令<br><a href="http://dblab.xmu.edu.cn/blog/1892/" target="_blank" rel="noopener">Hive的可视化操作(Hue)</a><br><a href="http://gethue.com/getting-started-with-hue-in-2-minutes-with-docker/" target="_blank" rel="noopener">Hue官方教程</a><br><a href="https://www.cnblogs.com/smartloli/p/4527168.html" target="_blank" rel="noopener">高可用Hadoop平台－Hue In Hadoop</a></p>
<h3 id="爬坑-2"><a href="#爬坑-2" class="headerlink" title="爬坑"></a>爬坑</h3><p>mysql的连接jar版本；<br>HDFS的文件、缓存似乎也有影响<br>mysql的账号密码很坑<br>hive的配置修改一定不能错</p>
<h2 id="sqoop"><a href="#sqoop" class="headerlink" title="sqoop"></a>sqoop</h2><p>Sqoop(发音：skup)是一款开源的工具，主要用于在Hadoop(Hive)与传统的数据库(mysql、postgresql…)间进行数据的传递，可以将一个关系型数据库（例如 ： MySQL ,Oracle ,Postgres等）中的数据导进到Hadoop的HDFS中，也可以将HDFS的数据导进到关系型数据库中。</p>
<h3 id="经典教程-1"><a href="#经典教程-1" class="headerlink" title="经典教程"></a>经典教程</h3><p><a href="http://dblab.xmu.edu.cn/blog/install-sqoop1/" target="_blank" rel="noopener">Ubuntu安装Sqoop</a><br><a href="http://dblab.xmu.edu.cn/blog/959/" target="_blank" rel="noopener">大数据案例-步骤一:本地数据集上传到数据仓库Hive</a><br><a href="http://dblab.xmu.edu.cn/blog/1005/" target="_blank" rel="noopener">大数据案例-步骤二：Hive数据分析</a><br><a href="http://dblab.xmu.edu.cn/blog/1059-2/" target="_blank" rel="noopener">大数据案例-步骤三：Hive、MySQL、HBase数据互导</a><br><a href="http://dblab.xmu.edu.cn/blog/1130-2/" target="_blank" rel="noopener">大数据案例-步骤四:利用R进行数据可视化分析</a></p>
<h2 id="scala"><a href="#scala" class="headerlink" title="scala"></a>scala</h2><p>Scala是一门现代的多范式编程语言，平滑地集成了面向对象和函数式语言的特性，旨在以简练、优雅的方式来表达常用编程模式。Scala的设计吸收借鉴了许多种编程语言的思想，只有很少量特点是Scala自己独有的。Scala语言的名称来自于“可伸展的语言”，从写个小脚本到建立个大系统的编程任务均可胜任。Scala运行于Java平台（JVM，Java 虚拟机）上，并兼容现有的Java程序，Scala代码可以调用Java方法，访问Java字段，继承Java类和实现Java接口。在面向对象方面，Scala是一门非常纯粹的面向对象编程语言，也就是说，在Scala中，<strong>每个值都是对象，每个操作都是方法调用</strong>。</p>
<p>Spark的设计目的之一就是使程序编写更快更容易，这也是Spark选择Scala的原因所在。</p>
<p><a href="http://dblab.xmu.edu.cn/blog/926-2/" target="_blank" rel="noopener">Scala简介</a></p>
<h3 id="经典教程-2"><a href="#经典教程-2" class="headerlink" title="经典教程"></a>经典教程</h3><p><a href="http://dblab.xmu.edu.cn/blog/spark/" target="_blank" rel="noopener">子雨大数据之Spark入门教程（Scala版）</a>  🐂🍺<br><a href="http://dblab.xmu.edu.cn/blog/929-2/" target="_blank" rel="noopener">Scala安装</a></p>
<h2 id="Spark"><a href="#Spark" class="headerlink" title="Spark"></a>Spark</h2><h3 id="经典教程-3"><a href="#经典教程-3" class="headerlink" title="经典教程"></a>经典教程</h3><p><a href="http://dblab.xmu.edu.cn/blog/python/" target="_blank" rel="noopener">厦门大学的Python入门教程</a><br><a href="http://dblab.xmu.edu.cn/blog/1709-2/" target="_blank" rel="noopener">子雨大数据之Spark入门教程(Python版)</a></p>
<h2 id="zookeeper"><a href="#zookeeper" class="headerlink" title="zookeeper"></a>zookeeper</h2><p>ZooKeeper是一个分布式的，开放源码的分布式应用程序协调服务，是Google的Chubby一个开源的实现，是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件，提供的功能包括：配置维护、域名服务、分布式同步、组服务等。<br>ZooKeeper的目标就是封装好复杂易出错的关键服务，将简单易用的接口和性能高效、功能稳定的系统提供给用户。<br>ZooKeeper包含一个简单的原语集， 提供Java和C的接口。<br>ZooKeeper代码版本中，提供了分布式独享锁、选举、队列的接口，代码在zookeeper-3.4.3\src\recipes。其中分布锁和队列有Java和C两个版本，选举只有Java版本。</p>

      
    </div>
    
    
    

      <div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

  
</div>

<div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/Hadoop入门笔记/">Hadoop入门笔记</a></p>
  <p><span>文章作者:</span></a>Chao</p>
  <p><span>发布时间:</span>2019年06月01日 - 09:06</p>
  <p><span>最后更新:</span>2019年06月01日 - 20:06</p>
  <p><span>原始链接:</span><a href="/Hadoop入门笔记/" title="Hadoop入门笔记">http://xchcloud.cn/Hadoop入门笔记/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="http://xchcloud.cn/Hadoop入门笔记/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
      $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
        });
    });  
</script>

      
</div>

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Hadoop/" <i class="fa fa-tag"></i> Hadoop</a>
          
            <a href="/tags/spark/" <i class="fa fa-tag"></i> spark</a>
          
            <a href="/tags/hive/" <i class="fa fa-tag"></i> hive</a>
          
            <a href="/tags/hbase/" <i class="fa fa-tag"></i> hbase</a>
          
            <a href="/tags/MapReduce/" <i class="fa fa-tag"></i> MapReduce</a>
          
            <a href="/tags/sqoop/" <i class="fa fa-tag"></i> sqoop</a>
          
            <a href="/tags/scala/" <i class="fa fa-tag"></i> scala</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/web协议详解与抓包实战/" rel="next" title="web协议详解与抓包实战">
                <i class="fa fa-chevron-left"></i> web协议详解与抓包实战
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/链接整理/" rel="prev" title="链接整理">
                链接整理 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://tuchuang-xchcloud-1253428588.cos.ap-chengdu.myqcloud.com/blog/header.jpg"
               alt="John Doe" />
          </span></a>Chao</p>


           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">60</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">33</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">65</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/lhc0101" target="_blank" title="Github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                    
                      Github
                    
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=qJmcmp_akJ6ZmZHo2dmGy8fF" target="_blank" title="E-mail">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                    
                      E-mail
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              dalao&nbsp;
              <i class="fa  fa-fw fa-globe"></i>
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://giracle.cn" title="DJG" target="_blank">DJG</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://owencxc.github.io" title="CX" target="_blank">CX</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.myzwl.win" title="ZWL" target="_blank">ZWL</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wuliekun.me/" title="WLK" target="_blank">WLK</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://Li-rr.github.io" title="LRR" target="_blank">LRR</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://dh.xchcloud.cn" title="导航" target="_blank">导航</a>
                </li>
              
            </ul>
+        <div id="days"></div>
</script>
<script language="javascript">
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("06/26/2018 12:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>

          </div>
         

-        <div id="days"></div>
</script>
<script language="javascript">
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("06/26/2018 12:00:00");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=setzero(Math.floor(e_hrsold));
e_minsold=(e_hrsold-hrsold)*60;
minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
seconds=setzero(Math.floor((e_minsold-minsold)*60));
document.getElementById('days').innerHTML="已运行"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
function setzero(i){
if (i<10)
{i="0" + i};
return i;
}
show_date_time();
</script>


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Hadoop-安装以及（伪）分布式集群"><span class="nav-number">1.</span> <span class="nav-text">Hadoop 安装以及（伪）分布式集群</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程："><span class="nav-number">1.1.</span> <span class="nav-text">经典教程：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#注解："><span class="nav-number">1.2.</span> <span class="nav-text">注解：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#hadoop-命令"><span class="nav-number">1.3.</span> <span class="nav-text">hadoop 命令</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#利用Java-API与HDFS进行交互"><span class="nav-number">2.</span> <span class="nav-text">利用Java API与HDFS进行交互</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程：-1"><span class="nav-number">2.1.</span> <span class="nav-text">经典教程：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#爬坑"><span class="nav-number">2.2.</span> <span class="nav-text">爬坑</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hbase"><span class="nav-number">3.</span> <span class="nav-text">hbase</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程：-2"><span class="nav-number">3.1.</span> <span class="nav-text">经典教程：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#笔记"><span class="nav-number">3.2.</span> <span class="nav-text">笔记</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HBase-常用Shell命令"><span class="nav-number">3.3.</span> <span class="nav-text">HBase 常用Shell命令</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#表的管理"><span class="nav-number">3.3.1.</span> <span class="nav-text">表的管理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#权限管理"><span class="nav-number">3.3.2.</span> <span class="nav-text">权限管理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#表数据的增删改查"><span class="nav-number">3.3.3.</span> <span class="nav-text">表数据的增删改查</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#添加数据"><span class="nav-number">3.3.3.1.</span> <span class="nav-text">添加数据</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#查询数据"><span class="nav-number">3.3.3.2.</span> <span class="nav-text">查询数据</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#删除数据"><span class="nav-number">3.3.3.3.</span> <span class="nav-text">删除数据</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#组命令Group-name"><span class="nav-number">3.3.4.</span> <span class="nav-text">组命令Group name</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Region管理"><span class="nav-number">3.3.5.</span> <span class="nav-text">Region管理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#配置管理及节点重启"><span class="nav-number">3.3.6.</span> <span class="nav-text">配置管理及节点重启</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MapReduce"><span class="nav-number">4.</span> <span class="nav-text">MapReduce</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程：-3"><span class="nav-number">4.1.</span> <span class="nav-text">经典教程：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#爬坑-1"><span class="nav-number">4.2.</span> <span class="nav-text">爬坑</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Hive-（数据仓库工具）"><span class="nav-number">5.</span> <span class="nav-text">Hive （数据仓库工具）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程"><span class="nav-number">5.1.</span> <span class="nav-text">经典教程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#爬坑-2"><span class="nav-number">5.2.</span> <span class="nav-text">爬坑</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sqoop"><span class="nav-number">6.</span> <span class="nav-text">sqoop</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程-1"><span class="nav-number">6.1.</span> <span class="nav-text">经典教程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#scala"><span class="nav-number">7.</span> <span class="nav-text">scala</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程-2"><span class="nav-number">7.1.</span> <span class="nav-text">经典教程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Spark"><span class="nav-number">8.</span> <span class="nav-text">Spark</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#经典教程-3"><span class="nav-number">8.1.</span> <span class="nav-text">经典教程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#zookeeper"><span class="nav-number">9.</span> <span class="nav-text">zookeeper</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Chao</span>
</div>



<div class="theme-info">
  <span class="post-count">博客全站共118.7k字</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">访客数</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">访客总量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>


        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  









  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/three/three.min.js"></script>

  
  <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.2"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.2"></script>


  

  

</body>
</html>
